(function() {
  var UserDeleteConfirm,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.AdminUserListingView = (function(_super) {

    __extends(AdminUserListingView, _super);

    function AdminUserListingView() {
      return AdminUserListingView.__super__.constructor.apply(this, arguments);
    }

    AdminUserListingView.prototype.el = $('#content');

    AdminUserListingView.prototype.initialize = function() {
      AdminUserListingView.__super__.initialize.apply(this, arguments);
      this.model.bind("change", this.render);
      return this.model.fetch();
    };

    AdminUserListingView.prototype.render = function() {
      var _this = this;
      this.Navigate(this.model.url(), false, true);
      return this.GetTemplate(SiteMap.Admin.Users.ListingTemplate, function(compiledTemplate) {
        return $(_this.el).html(compiledTemplate(_this.model.toJSON()));
      });
    };

    AdminUserListingView.prototype.events = {
      "click .search": "search",
      "click .pagination a": "pagination",
      "click th>a": "sort",
      "click .buttons>.create": "create",
      "click .buttons>.delete": "remove",
      "click tbody tr>td:not(.chk)": "edit",
      "change .page-size": "changeSize",
      "click .reset": "reset"
    };

    AdminUserListingView.prototype.search = function(event) {
      var email, login;
      event.preventDefault();
      email = $("#Filter_Email").val();
      login = $("#Filter_Login").val();
      if (((email != null) && email !== '') || ((login != null) && login !== '')) {
        Messages.WriteMessage('Apply search.');
        Loading.Start();
        this.model.set({
          "Filter": {
            Email: email,
            Login: login
          }
        }, {
          silent: true
        });
        return this.model.fetch();
      }
    };

    AdminUserListingView.prototype.reset = function(event) {
      Loading.Start();
      $("#Filter_Email").val('');
      $("#Filter_Login").val('');
      this.model.set({
        "Filter": {
          "Email": '',
          "Login": ''
        }
      }, {
        silent: true
      });
      return this.model.fetch();
    };

    AdminUserListingView.prototype.remove = function(event) {
      var confirmDialog, form;
      event.preventDefault();
      Messages.Clear();
      form = $(this.el).find("form.listing");
      if (form.find("input:checked").length) {
        confirmDialog = new UserDeleteConfirm(this);
        return confirmDialog.Show("Are you sure?");
      } else {
        return Messages.WriteMessage("Choose one or more users.");
      }
    };

    AdminUserListingView.prototype.create = function(event) {
      event.preventDefault();
      Loading.Start();
      return this.Navigate(SiteMap.Admin.Users.Create, true);
    };

    return AdminUserListingView;

  })(ListingView);

  UserDeleteConfirm = (function(_super) {

    __extends(UserDeleteConfirm, _super);

    function UserDeleteConfirm(view) {
      this.view = view;
    }

    UserDeleteConfirm.prototype.Ok = function() {
      var data, form,
        _this = this;
      form = $(this.view.el).find("form.listing");
      data = form.serialize();
      Loading.Start();
      Messages.WriteMessage("Deleting users");
      return $.post(SiteMap.Admin.Users.Delete, data, function(response) {
        if ((response.SuccessMessage != null) && response.SuccessMessage.length) {
          Messages.WriteSuccessMessage(response.SuccessMessage);
          return _this.view.model.fetch();
        } else {
          Messages.WriteErrors(response.Errors);
          return Loading.Stop();
        }
      });
    };

    return UserDeleteConfirm;

  })(ConfirmDialog);

}).call(this);
